import os
from celery import Celery
from celery.schedules import crontab
from django.conf import settings

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')

app = Celery('host_management')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()

# 定时任务配置
app.conf.beat_schedule = {
    'change-passwords-every-8-hours': {
        'task': 'management.tasks.change_host_passwords',
        'schedule': crontab(minute=0, hour='*/8'),
    },
    'generate-daily-stats': {
        'task': 'management.tasks.generate_host_statistics',
        'schedule': crontab(minute=0, hour=0),
    },
    'check-hosts-reachable-hourly': {
        'task': 'management.tasks.check_hosts_reachable',
        'schedule': crontab(minute=0, hour='*/1'),
    },
}